<template>
	<view class="diag">
		<!-- 开头 -->
		<view class="diag_title">
			<image class="title_image" :src="dataobj.img"></image>
			<view class="title_box">
				<view class="font15 font-323232 font-b">{{dataobj.name}}</view>
				<view class="font14 font-7d766b">{{dataobj.hospital_info?dataobj.hospital_info.addr:''}}</view>
				<view class="font14 font-7d766b">{{dataobj.room_name}} | {{dataobj.academic_title_name.name}}</view>
			</view>
		</view>
		<!-- 边框 -->
		<!-- <view class="com_border" v-if="type"></view> -->
		<!-- 预约时间 -->
		<!-- 		<view class="timeorder" v-if="type">
			<view class="title_bos font15 font-323232 font-b">可预约时间</view>
			<view class="timeorder_bos font14 font-323232" @click="Ontimeorder">
				<view>7月10号 上午 9:30~10:30</view>
				<view>{{timetext==''?'请选择预约时间':timetext}}</view>
				<view class="font15 font-323232">></view>
			</view>
		</view> -->
		<!-- 边框 -->
		<view class="com_border"></view>
		<!-- 就诊人 -->
		<view class="seeadoctor">
			<view class="ComPopup_choois">
				<text class="font-32323 font15 font-b">请选择就诊人</text>
				<text
					class="ComPopup_chooisa font-989898 font14">({{familyobj.the_patient_info.name?familyobj.the_patient_info.name+'卡号:'+familyobj.the_patient_info.code:'暂无'}})</text>
			</view>
			<view class="ComPopup_list">
				<view class="ComPopup_listname" :class="item.id==familyobj.id?'listname_a':'listname_b'"
					v-for="(item,index) in familyList" :key="index" @click="Onchooisfamily(item)">
					{{item.the_patient_info.namea}}
				</view>
				<view class="ComPopup_listadd" @click="Onjzrgladd">+</view>
			</view>
		</view>
		<!-- 边框 -->
		<view class="com_border"></view>
		<!-- 咨询目的 -->
		<view class="objective">
			<view class="title_bos font15 font-323232 font-b">本次咨询目的</view>
			<view :class="item.show?'objective_a':'objective_b'" @click="Oncausechioess(item)"
				class="objective_List font14" v-for="(item,index) in causeList" :key="index">{{item.name}}</view>
		</view>
		<!-- 边框 -->
		<view class="com_border"></view>
		<!-- 病情描述 -->
		<view class="describe">
			<view class="title_bos font15 font-323232 font-b">病情描述</view>
			<textarea @input="Ondescribe" placeholder-class="placeholderClass" class="describe_textarea"
				placeholder="请详细描述就诊人的性别，年龄，症状，持续时间和用药情况，或已经确诊的疾病以及看诊医生的意见，我们会确保您的隐私安全。(最少10个字)" />
		</view>
		<!-- 添加图片 -->
		<view class="add_image">
			<view class="addimage_img" @click="Onopen">
				<image src="../../static/add.png" mode=""></image>
			</view>
			<view class="addimage_bos">
				<text class="font15 font-323232">添加图片</text>
				<view class="font13 font-7d766b">病状部位,检查报告或者其它病情资料(最多可上传4张)</view>
			</view>
		</view>
		<!-- 图片列表 -->
		<view class="upload_bos">
			<view class="upload_list" v-for="(item,index) in uploadList" :key="index">
				<image class="upload_info" :src="item" mode="aspectFill"></image>
				<image @click="Onclose(index)" class="upload_close" src="../../static/close_a.png" mode=""></image>
			</view>
		</view>
		<!-- 提交问诊 -->
		<view class="qx_button">
			<view @click="Onadd" class="font-323232 font16">提交问诊</view>
		</view>
		<!-- 下拉弹窗 -->
		<uni-popup ref="Compopup" type="bottom" @change="Onchange">
			<view class="popup_bos">
				<view class="up_choicea" @click="Onalbum('album')">从相册中选择</view>
				<view class="up_choicebor"></view>
				<view class="up_choiceb" @click="Onalbum('camera')">拍照</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	export default {
		components: {
			uniPopup
		},
		data() {
			return {
				id: null,
				dataobj: {}, //医生详情
				type: false,
				typename: '', //类型
				familyList: [], //就诊人列表
				familyobj: {}, //默认就诊人
				causeList: [], //咨询目的列表
				cause: '', //咨询目的
				describe: '', //病情说明
				uploadList: [], //图片
				options: '', //类型
				timetext: '', //预约时间
				day: '', //日期
				week: '', //周几
				begin: '', //开始时间
				end: '', //结束时间
				causeID: null,
			}
		},
		onLoad: function(options) {
			this.type = options.type == 'sp' ? true : false
			this.typename = options.type
			this.id = options.id
			if (options.type == 'sp' && options.day) {
				this.timetext = options.day + ' ' + options.week + ' ' + options.begin + ' ' + options.end
				this.day = options.day
				this.week = options.week
				this.begin = options.begin
				this.end = options.end
			}
			//医生详情
			this.Ondoctordetails()
			//获取就诊人
			this.Onlistmemberfamily()
			//咨询目的列表
			this.Oncause()
		},
		methods: {
			//详情
			Ondoctordetails() {
				this.$Http({
					url: 'doctorDetails',
					data: {
						doctor_id: this.id,
					}
				}).then(res => {
					res.data.img = this.$store.state.http_img + res.data.img
					this.dataobj = res.data
				})
			},
			//获取就诊人
			Onlistmemberfamily() {
				this.$Http({
					url: 'listThePatient',
					data: {}
				}).then(res => {
					if (!res.data || res.data.length == 0) {} else {
						this.familyList = res.data
						this.familyobj = res.data[0] ? res.data[0] : {}
						res.data.forEach(item => {
							item.the_patient_info.namea = item.the_patient_info.name.substring(item
								.the_patient_info.name.length - 2)
							if (item.is_default == 1) {
								this.familyobj = item
							}
						})
					}
				})
			},
			//选择就诊人
			Onchooisfamily(e) {
				this.familyobj = e
			},
			//添加就诊人
			Onjzrgladd() {
				this.$store.commit('Onjzkurl', '/pagesA/ask/diag?id=' + this.id + '&type=' + this.typename)
				uni.navigateTo({
					url: '/pagesA/my/jzrgladd',
				})
			},
			//咨询目的
			Oncause() {
				this.$Http({
					url: 'consultationConsult',
					data: {}
				}).then(res => {
					if (res.code == 1) {
						res.data.consultation_consult.forEach(item => {
							item.show = false
						})
						res.data.consultation_consult[0].show = true
						this.cause = res.data.consultation_consult[0].name
						this.causeID = res.data.consultation_consult[0].id
						this.causeList = res.data.consultation_consult
					}
				})
			},
			//选择咨询目的
			Oncausechioess(e) {
				this.causeList.forEach(item => {
					item.show = false
					if (item.id == e.id) {
						item.show = true
					}
				})
				this.cause = e.name
				this.causeID = e.id
			},
			//病情说明
			Ondescribe(e) {
				this.describe = e.detail.value
			},
			//打开上传图标弹窗
			Onopen() {
				this.$refs.Compopup.open()
			},
			Onchange() {},
			//上传图片
			Onalbum(choois) {
				let that = this
				let list = this.uploadList
				let count = 4 - list.length
				uni.chooseImage({
					count: count,
					sizeType: ['original', 'compressed'],
					sourceType: [choois],
					success(res) {
						let exceed = true
						res.tempFiles.forEach(item => {
							if (item.size > 1000000) {
								exceed = false
							}
						})
						that.$refs.Compopup.close()
						if (!exceed) {
							uni.showToast({
								title: '上传图片大于1M请重新上传',
								icon: 'none',
								duration: 2000
							})
							return
						}
						uni.showLoading({
							title: '上传中',
							mask: true
						});
						res.tempFilePaths.forEach(item => {
							uni.uploadFile({
								url: that.$Config.http_static + 'api/common/uploader',
								filePath: item,
								name: 'file',
								success: function(res1) {
									let resdata = JSON.parse(res1.data)
									if (resdata.code == 1) {
										that.uploadList.push(resdata.data.fullurl)
									} else {
										uni.showToast({
											title: resdata.msg,
											icon: 'none',
											duration: 2000
										})
									}
								},
								fail: function(res) {}
							})
						})
						uni.hideLoading();
					},
					fail(res) {
						uni.showToast({
							title: '上传图片失败',
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			//删除照片
			Onclose(e) {
				this.uploadList.splice(e, 1)
			},
			//选择预约时间
			Ontimeorder() {
				uni.navigateTo({
					url: '/pagesA/ask/chooistime?id=' + this.id,
				})
			},
			//切换的事件
			onChange(event) {
				const {
					picker,
					value,
					index
				} = event.detail;
				picker.setColumnValues(1, value[0].values);
			},
			//提交
			Onadd() {
				if (this.familyobj.id == undefined) {
					uni.showToast({
						title: '请选择就诊人',
						icon: 'none',
						duration: 2000
					})
					return
				}
				if (this.describe == '' || this.describe.length < 10) {
					uni.showToast({
						title: '请填写病情描述并且至少10个字',
						icon: 'none',
						duration: 2000
					})
					return
				}
				let data = {
					doctor_id: this.id,
					consultation_consult_id: this.causeID,
					content: this.describe,
					the_patient_id: this.familyobj.the_patient_info.id,
				}
				let img = ''
				let url = ''
				if (this.uploadList.length > 0) {
					this.uploadList.forEach(item => {
						img = img + item + ','
					})
					data.images = img
				}

				if (this.typename == 'tw') {
					url = 'createConsultationOrder'
				}
				if (this.typename == 'sp') {
					url = 'createConsultationVideoOrder'
				}
				this.$Http({
					url: url,
					data: data,
					show: true,
					type: 'post'
				}).then(res => {
					if (res.code == 1) {
						uni.navigateTo({
							url: '/pagesA/ask/payment?id=' + res.data.order_code + '&type=' + this.typename,
						})
					}
				})

			}
		}
	}
</script>

<style>
	.diag {
		padding-bottom: 160rpx;
	}

	/* 开头 */
	.diag_title {
		padding: 60rpx 30rpx 20rpx 30rpx;
		display: flex;
	}

	.title_image {
		width: 126rpx;
		height: 168rpx;
		border-radius: 12rpx;
	}

	.title_box {
		width: 564rpx;
		padding-left: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.timeorder {
		padding: 10rpx 30rpx 30rpx 30rpx;
	}

	.timeorder_bos {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.title_bos {
		height: 80rpx;
		line-height: 80rpx;
	}

	/* 就诊人 */
	.ComPopup_choois {
		margin: 44rpx 0 24rpx 25rpx;
		display: flex;
		align-items: center;
	}

	.ComPopup_chooisa {
		margin-left: 20rpx;
	}

	.ComPopup_list {
		display: flex;
		flex-wrap: wrap;
		padding-left: 25rpx;
	}

	.ComPopup_list view {
		margin-right: 44rpx;
		margin-bottom: 40rpx;
	}

	.ComPopup_list view:nth-of-type(5n) {
		margin-right: 0rpx;
	}

	.ComPopup_listname {
		font-size: 28rpx;
		color: #fff;
		height: 104rpx;
		width: 104rpx;
		border-radius: 52rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.listname_a {
		background-color: #6bcbb6;
		color: #fff;
	}

	.listname_b {
		background-color: #fff;
		color: #6bcbb6;
		border: 2rpx solid #6bcbb6;
	}

	.ComPopup_listadd {
		height: 104rpx;
		width: 104rpx;
		border-radius: 52rpx;
		border: 2rpx solid #6bcbb6;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 50rpx;
		color: #6bcbb6;
	}

	/* 咨询目的 */
	.objective {
		padding: 10rpx 30rpx;
	}

	.objective_List {
		padding: 16rpx 18rpx;
		/* border: 1rpx #ececec solid; */
		border-radius: 20rpx;
		display: inline-block;
		margin-right: 40rpx;
		margin-bottom: 30rpx;
	}

	.objective_a {
		color: #6ccbb6;
		border: 1rpx #6ccbb6 solid;
		/* color: #9a9a9a; */
	}

	.objective_b {
		color: #dfdfdf;
		border: 1rpx #dfdfdf solid;
		/* color: #dfdfdf; */
	}

	/* 病情描述 */
	.describe {
		padding: 10rpx 30rpx;
	}

	.describe_textarea {
		width: 690rpx;
		min-height: 160rpx;
		padding: 20rpx;
		background-color: #f9f9f9;
		border-radius: 20rpx;
	}

	.placeholderClass {
		font-size: 28rpx;
		color: #989898;
		line-height: 50rpx;
	}

	.describe_textarea {
		font-size: 28rpx;
	}

	/* 添加图片 */
	.add_image {
		padding: 10rpx 30rpx;
		display: flex;
	}

	.addimage_img {
		width: 140rpx;
		height: 140rpx;
		border-radius: 10rpx;
		background-color: #f5f5f5;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.addimage_img image {
		width: 50rpx;
		height: 50rpx;
	}

	.addimage_bos {
		width: 550rpx;
		height: 140rpx;
		padding-left: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	/* 图片列表 */
	.upload_bos {
		width: 750rpx;
		margin-top: 20rpx;
		display: flex;
		flex-wrap: wrap;
		padding: 0 30rpx;
	}

	.upload_list {
		width: 150rpx;
		height: 150rpx;
		position: relative;
		margin-right: 30rpx;
	}

	.upload_list:nth-of-type(4n) {
		margin-right: 0rpx;
	}

	.upload_info {
		width: 150rpx;
		height: 150rpx;
		background-color: #ffffff;
	}

	.upload_close {
		position: absolute;
		top: -15rpx;
		right: -15rpx;
		width: 30rpx;
		height: 30rpx;
	}

	/* 提交 */
	.qx_button {
		width: 750rpx;
		height: 120rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #f9f9f9;
		z-index: 2;
	}

	.qx_button view {
		width: 650rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		margin-left: 50rpx;
		margin-top: 20rpx;
		background-color: #6bcbb6;
		color: #fff;
	}

	/* 选择按钮 */
	.popup_bos {
		background-color: #FFFFFF;
		z-index: 999;
		position: relative;
	}

	.up_choicea {
		width: 750rpx;
		text-align: center;
		padding: 35rpx 0;
		font-size: 30rpx;
		color: #4a4747;
	}

	.up_choiceb {
		width: 750rpx;
		text-align: center;
		padding: 35rpx 0;
		font-size: 30rpx;
		color: #4a4747;
	}

	.up_choicebor {
		width: 700rpx;
		height: 2rpx;
		background-color: #f6f6f6;
		margin: 0 auto;
	}
</style>
